package com.kly.cashmall.widget.picker;

import android.text.TextUtils;

import java.io.File;
import java.io.FileInputStream;

/**
 * @author
 * @date 2017/6/20
 */
public class FileUtil {

  public static boolean isFileExist(String filePath) {
    return !TextUtils.isEmpty(filePath) && new File(filePath).exists();
  }

  public static long getFileSize(String filePath) {
    long size;
    if (TextUtils.isEmpty(filePath)) {
      return 0;
    }
    try {
      if (!new File(filePath).exists()) {
        return 0;
      }
      FileInputStream fis = new FileInputStream(filePath);
      size = fis.available();
      fis.close();
    } catch (Exception e) {
      e.printStackTrace();
      return 0;
    }
    return size;
  }

  /**
   * 删除文件或者文件夹
   */
  public static boolean deleteFile(String fileName) {
    if (fileName != null && fileName.length() > 0) {
      File file = new File(fileName);
      if (file.exists()) {
        return file.delete();
      }
    }
    return false;
  }
}
